package cc.surui.logic 
{
	import cc.surui.ui.fl.UIBird;
	import cc.surui.ui.fl.UIBlackBirdBig;
	import cc.surui.ui.fl.UIGreenPigBig;
	import cc.surui.ui.fl.UIPurpleBirdBig;
	import cc.surui.ui.fl.UIRedBirdBig;
	import cc.surui.ui.fl.UIYellowBirdBig;
	import flash.geom.Point;
	/**
	 * ...
	 * @author Surui
	 */
	public class AppleRunner 
	{
		private var _birds:Object = new Object();
		private var _places:Object = new Object();
		private var _selected:UIBird;
		private var _time:int = 1;
		private var _frams:int = 0;
		private var _index:int = 0;
		private static var _self:AppleRunner;
		private var _start:Boolean = false;
		public function AppleRunner() 
		{
			_birds = {
				0:new UIBlackBirdBig(),
				1:new UIGreenPigBig(),
				2:new UIPurpleBirdBig(),
				3:new UIRedBirdBig(),
				4:new UIYellowBirdBig(),
				5:new UIBlackBirdBig(),
				6:new UIGreenPigBig(),
				7:new UIPurpleBirdBig(),
				8:new UIRedBirdBig(),
				9:new UIYellowBirdBig(),
				10:new UIBlackBirdBig(),
				11:new UIGreenPigBig(),
				12:new UIPurpleBirdBig(),
				13:new UIRedBirdBig(),
				14:new UIYellowBirdBig(),
				15:new UIBlackBirdBig(),
				16:new UIGreenPigBig(),
				17:new UIPurpleBirdBig(),
				18:new UIRedBirdBig(),
				19:new UIYellowBirdBig(),
				20:new UIBlackBirdBig(),
				21:new UIGreenPigBig(),
				22:new UIPurpleBirdBig(),
				23:new UIRedBirdBig()
			}
			_places = {
				0:new Point(30,-5),
				1:new Point(110,-25),
				2:new Point(180,-3),
				3:new Point(265,0),
				4:new Point(345,-15),
				5:new Point(420,-5),
				6:new Point(500, -25),
				7:new Point(565, -3),
				8:new Point(655, 0),
				
				9:new Point(650,60),
				10:new Point(650,145),
				11:new Point(655, 200),
				
				12:new Point(645,300),
				13:new Point(575,305),
				14:new Point(500,290),
				15:new Point(420,300),
				16:new Point(345,280),
				17:new Point(255,300),
				18:new Point(190,310),
				19:new Point(115,290),
				
				20:new Point(30,300),
				21:new Point(33,205),
				22:new Point(20,145),
				23:new Point(30,80)
			}
			
		}
		public function update():void {
			if ( !_start ) {
				return;
			}
			if ( !_selected ) {
				_index = 0;
				_selected = _birds[0];
				_birds[_index].light = true;
			} else {
				_frams ++;
			}
			if ( _frams >= _time ) {
				_birds[_index].light = false;
				var len:int = _frams / _time;
				_index = _index + len;
				if ( _index > 22 ) {
					_index = _index % 23;
				}
				_birds[_index].light = true;
				_frams = _frams % _time;
			}
		}
		
		public function start():void {
			this._start = true;
		}
		
		public static function get self():AppleRunner {
			if ( !_self ) {
				_self = new AppleRunner();
			}
			return _self;
		}
		
		public function get birds():Object 
		{
			return _birds;
		}
		
		public function set birds(value:Object):void 
		{
			_birds = value;
		}
		
		public function get places():Object 
		{
			return _places;
		}
		
		public function set places(value:Object):void 
		{
			_places = value;
		}
		
	}

}